//原型模式  在一个对象中申明一个clone()方法
//用于保存对象当前的状态
//原型模式要注意深拷贝和浅拷贝的区别
#include <iostream>
#include <string>
#include <memory>
//类似于拷贝构造
class Resume
{
public:
    using ptr=std::shared_ptr<Resume>;
    Resume(){};
    Resume(const std::string& name, const int& age, const std::string& desc):
    m_name(name),m_age(age),m_desc(desc){}
    std::string getName(){return m_name;}
    void setName(const std::string& name){m_name=name;}
    int getAge(){return m_age;}
    void setAge(const int& age){m_age=age;}
    std::string getDesc(){return m_desc;}
    void setDesc(const std::string& desc){m_desc=desc;}
    void displayInfo()
    {
        std::cout<<"name:"<<m_name<<std::endl;
        std::cout<<"age:"<<m_age<<std::endl;
        std::cout<<"description:"<<m_desc<<std::endl;
    }
    Resume::ptr clone()
    {
        Resume::ptr resumeCopy(new Resume);
        resumeCopy->m_name=this->m_name;
        resumeCopy->m_age=this->m_age;
        resumeCopy->m_desc=this->m_desc;
        return resumeCopy;
    }
private:
    std::string m_name;
    int m_age;
    std::string m_desc;
};

int main(int argc, char** argv)
{
    Resume::ptr resume1(new Resume("daniel",18,"work for 5 years"));
    std::cout<<"*****resume1******"<<std::endl;
    resume1->displayInfo();
    resume1->setName("Alice");
    Resume::ptr resume2=resume1->clone();
    std::cout<<"*****resume2******"<<std::endl;
    resume2->displayInfo();
    resume2->setDesc("I love daniel");
    Resume::ptr resume3=resume2->clone();
    std::cout<<"*****resume3******"<<std::endl;
    resume3->displayInfo();
    return 0;
}